<?php

class Admin_Form_ChangePassword extends Zend_Form {
	
	const OLD_PASSWORD_LABEL     = 'Mật khẩu hiện tại';
	const NEW_PASSWORD_LABEL     = 'Mật khẩu mới';
	const PASSWORD_MIN_LENGTH    = 6;
	const PASSWORD_MAX_LENGTH    = 32;
	const ENCODING               = 'UTF-8';

	public function init() {
		$this->setName('user');
		
		$id = new Zend_Form_Element_Hidden('id');
		$id->addFilter('Int');
		
		$passwordLength = new Zend_Validate_StringLength(self::PASSWORD_MIN_LENGTH, self::PASSWORD_MAX_LENGTH, self::ENCODING);
		
		$oldpassword = new Zend_Form_Element_Password('oldpassword');
		$oldpassword->setLabel(self::OLD_PASSWORD_LABEL)
					->setRequired(true)
					->addValidator('NotEmpty', true)
					->addFilter('StripTags')
					->addFilter('StringTrim')
					->setAttribs(array("maxlength" => "32"))
					->addValidator($passwordLength);
			
		$newpassword = new Zend_Form_Element_Password('newpassword');
		$newpassword->setLabel(self::NEW_PASSWORD_LABEL)
					->setRequired(true)
					->addValidator('NotEmpty', true)
					->addFilter('StripTags')
					->addFilter('StringTrim')
					->setAttribs(array("maxlength" => "32"))
					->addValidator($passwordLength);
		
		$submit = new Zend_Form_Element_Submit('submit');
		$submit->setAttrib('id', 'submitbutton')
			   ->setAttrib("class", "btn btn-large btn-primary ")
			   ->setLabel('Save')
			   ->removeDecorator('DtDdWrapper');
		
		$reset = new Zend_Form_Element_Reset('reset');
		$reset->setAttrib('id', 'resetbutton')
			  ->setAttrib("class", "btn btn-large")
			  ->setLabel('Reset')
			  ->removeDecorator('DtDdWrapper');
		
		$this->addElements(array($oldpassword, $newpassword, $submit, $reset));
		$this->addDisplayGroup(array('submit', 'reset'), 'buttons');
		$dg = $this->getDisplayGroup('buttons');
		$dg->removeDecorator('Fieldset');
		$dg->removeDecorator('HtmlTag');
	}
}

?>
